<template>
  <common-search :col-layout="{xxl: 6, xl:8, lg: 8, md: 12, sm: 24, xs: 24}" v-model="query" :formItems="formItems" @search="search" @reset="reset"></common-search>
  <a-button type="primary" @click="exports" :loading="exportLoading" v-modulePerm="['logPage:export']">
    <template #icon>
      <ExportOutlined />
    </template>
    导出
  </a-button>
  <common-table
      :columns="columns"
      :dataSource="dataList"
      v-model:localPagination="page"
      @paginationChange="onPageChange"
      v-model:loading="loading"
      :scroll="{ x: 'max-content'}"
  >

  </common-table>
</template>
<script>
export default {
  name:'inventoryPools-logPage'
}
</script>
<script setup>
import { ref,onMounted } from "vue";
import CommonTable from "@/components/commonTable/index.vue";
import CommonSearch from "@/components/commonSearch/index.vue";
import {useSearchTable} from "@/hooks/table/useSearchTable";
import {getManyDictItems} from "@/api/system/dict.js";
import {message} from "ant-design-vue";
import {postFile} from "@utils/service/index.js";
import {getVerifyLogPage} from "@/api/inventoryPools/logPage.js";
const columns = [
  {
    "dictCode": "site",
    "dataIndex": "site",
    "title": "站点",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "platform",
    "title": "平台",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "saleZone",
    "title": "订单区域",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "orderId",
    "title": "平台订单",
    "align": "center",
    "fieldType": "Date"
  },
  {

    "dataIndex": "saleOrderCode",
    "title": "易仓订单",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "productSku",
    "title": "平台sku",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "warehouseSku",
    "title": "仓库sku",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "poolCode",
    "title": "库存池",
    "align": "center",
    "fieldType": "Long"
  },
  {

    "dataIndex": "warehouseCode",
    "title": "库存仓库",
    "align": "center",
    "fieldType": "Long"
  },
  {
    "dataIndex": "evaZone",
    "title": "仓库区域",
    "align": "center",
    "fieldType": "Long"
  },
  {
    "dataIndex": "logDetail",
    "title": "日志",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "createTime",
    "title": "时间",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "shipWarehouse",
    "title": "发货仓库",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "shipZone",
    "title": "发货区域",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "dateWarehouseShipping",
    "title": "发货日期",
    "align": "center",
    "fieldType": "String"
  },
]
const formItems = ref([
  {
    label:'易仓订单',
    type:'input',
    field:'saleOrderCode',
    options:[]
  },
  {
    label:"平台sku",
    type:'input',
    field: 'productSku',
  },
  {
    label:'仓库sku',
    type:'input',
    field:'warehouseSku',
  },
  {
    label:'库存池',
    type:'input',
    field:'poolCode',
  },
  {
    label:"库存仓库",
    type:'input',
    field: 'warehouseCode',
  },
  {
    label:"时间",
    type:'rangePicker',
    field: 'time',
    showTime: false,
  },
  {
    label:"平台订单",
    type:'input',
    field: 'orderId',
  },
  {
    label:"订单区域",
    type:'input',
    field: 'saleZone',
  },
  {
    label:"站点",
    type:'select',
    field: 'site',
    options:[]
  },
  {
    label:"发货日期",
    type:'rangePicker',
    field: 'time1',
    showTime: false,
  },
])
const selectedRowKeys = ref([])
const exportLoading = ref(false)
const { dataList, query, loading, page, search, reset, onPageChange } = useSearchTable({
  searchAPI: getVerifyLogPage,
  queryFactory: () => ({
  }),
  beforeSearch: () => {
    if(query.value.time){
      query.value.createTimeBegin = query.value.time[0]
      query.value.createTimeEnd = query.value.time[1]
    }else{
      delete query.value.createTimeBegin
      delete query.value.createTimeEnd
    }
    if(query.value.time1){
      query.value.dateWarehouseShippingBegin = query.value.time1[0]
      query.value.dateWarehouseShippingEnd = query.value.time1[1]
    }else{
      delete query.value.dateWarehouseShippingBegin
      delete query.value.dateWarehouseShippingEnd
    }
  },
});
/**
 * 初始化字典数据
 * @returns {Promise<void>}
 */
const init = async () => {
  try{
    const res = await getManyDictItems({
      dictCodeList:"site"
    })
    formItems.value[8].options = res.result.site
  }catch (e){
    console.log(e)
  }
}
/**
 *  选择行变化事件
 * @param e {Array} 选择行的keys
 */
const onSelectChange = (e) => {
  selectedRowKeys.value = e
}
const exports = async () => {
  try{
    exportLoading.value = true
    const res = await postFile('/inventoryPool/verify/log_detail_export','post',query.value,'审单日志.xlsx')
    message.success('导出成功')
  }catch (e) {
    message.error(e)
  }finally {
    exportLoading.value = false
  }
}
onMounted(()=>{
  init()
})
</script>
<style scoped>

</style>
